#include<stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


/*  ./led_test /dev/myled on 
 *  ./led_test /dev/myled off
 */
int main(int argc, char** argv)
{
   int fd;
   char status;
   
   if(argc != 3)
   	{
   	   printf("Usage:\n");
	   printf("%s <dev> on \n",argv[0]);
	   printf("%s <dev> off \n",argv[0]);
	   return -1;
   	}

   fd = open("/dev/myled", O_RDWR);
   if(fd == -1)
   	{
   	   printf("open %s err\n", argv[1]);
   	}

   status = 0; //默认关闭
   if(strcmp(argv[2],"on") == 0)
   	{
   	   //打开LED
   	   status = 1;
   	}
   
   write(fd, &status, 1);
   close(fd);
   
   return 0;
}
